//
//  SEExamineRecordRefractiveViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/26.
//

import UIKit

class SEExamineRecordRefractiveViewModel: SEExamineRecordBaseViewModel {


    override func heightForRow(indexPath: IndexPath) -> CGFloat {
        switch indexPath.section {
        case 0, 1: return 325
        case 2: return 160
        default: return 0
        }
    }

    func r1r2(index: Int) -> (r1: String, r2: String) {
        let model = examineRecordData(index: index)
        let r1Array = model.r1.components(separatedBy: ",")
        var r1 = ""
        if r1Array.count == 2 {
            r1 = "\(r1Array[0])mm  \(r1Array[1])D"
        }
        let r2Array = model.r2.components(separatedBy: ",")
        var r2 = ""
        if r2Array.count == 2 {
            r2 = "\(r2Array[0])mm  \(r2Array[1])D"
        }
        return (r1,r2)
    }

    override var resultDescription: String {
        var str = ""
        if showRight {
            let odData = examineRecordData(index: 0)
            str += " 右眼--球镜度数: \(odData.sph), 柱镜度数: \(odData.cyl), 轴位: \(odData.axial), R1: \(r1r2(index: 0).r1), R2: \(r1r2(index: 0).r2), AX: \(odData.ax);"
        }
        if showLeft {
            let osData = examineRecordData(index: 1)
            str += " 左眼--球镜度数: \(osData.sph), 柱镜度数: \(osData.cyl), 轴位: \(osData.axial), R1: \(r1r2(index: 1).r1), R2: \(r1r2(index: 1).r2), AX: \(osData.ax);"
        }
        return str
    }

}
